package controller;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;

import org.hibernate.mapping.Value;

import gui.pnlConsCargaMaquina;
import gui.pnlConsSituacaoFabrica;
import gui.pnlSimulacao;
import beans.TbBoleto;
import beans.TbMaquina;
import beans.TbOp;
import beans.TbParadamaquina;
import beans.TbProduto;
import beans.TbSetor;
import dao.TbBoletoDAO;
import dao.TbMaquinaDAO;
import dao.TbOpDAO;
import dao.TbParadamaquinaDAO;
import dao.TbPerfilDAO;
import dao.TbProdutoDAO;
import dao.TbProduzidoDAO;
import dao.TbSetorDAO;

public class SimulacaoContr {
	private pnlSimulacao window;
	final static String charEspeciais = "`~!@#$%^&*()_+=\\|\"':;?/>.<, "; 
	
	public SimulacaoContr(pnlSimulacao pnl) {
		window = pnl;
	}

	public boolean isNumerico(char c) {
		if(Character.isDigit(c))
			return true;
		else 
			return false; 
	}
	public boolean isEspecial(char c) {
		for(int i = 0; i < charEspeciais.length(); i++) {
			if(c == charEspeciais.charAt(i)) 
				return true;
		}
		
		return false;
	}


	public List<String> ListarOP() {
		
		TbOpDAO dao = new TbOpDAO();
	
		return dao.ListarOp();
	}
	
	public void PreencherTxts() {
		window.getTxtOpQtd().setText("");
		List <TbOp> ListaSet = RecuperaListOp();
			if (!ListaSet.isEmpty()){	
			for(TbOp q: ListaSet){
				
				String opQ = Long.toString(q.getOpQuantidade());
				String Praz = (q.getOpPrazofinal()).toString();
				String PrazOrd = ""+Praz.charAt(8)+Praz.charAt(9)+Praz.charAt(7)+Praz.charAt(5)+Praz.charAt(6)+Praz.charAt(4)+Praz.charAt(0)+Praz.charAt(1)+Praz.charAt(2)+Praz.charAt(3);
				
				String opProdCod = Integer.toString(q.getTbProduto().getProdutoCod());
				String opProdDescr = (q.getTbProduto().getProdutoDescr());
				
				window.getTxtOpQtd().setText(opQ);		
				window.getTxtOpPrazofinal().setText(PrazOrd);
				window.getTxtProdCod().setText(opProdCod);
				window.getTxtProdDescr().setText(opProdDescr);
				
				
				
				
			
			}
			}else
				window.getTxtOpQtd().setText("");
				}
	
	public void Boleto() {
		List <TbBoleto> ListaSet = RecuperaBoleto();
			if (!ListaSet.isEmpty()){	
				//window.getCmbBoletos().
			for(TbBoleto 	q: ListaSet){
				
				Long bol = (Long) q.getBoletoCod();
				window.getCmbBoletos().addItem(bol);
		}
			}else
				window.getTxtOpQtd().setText("");
				}
	
	public List <TbBoleto> RecuperaBoleto () {
		TbBoletoDAO dao = new TbBoletoDAO();
		long cond = (Long) window.getCmbOpCod().getSelectedItem();
		StringBuffer query = new StringBuffer ("from TbBoleto where boleto_codop = "+ cond); 
		return dao.listByQuery(query.toString());
	}
	
	
	public void BoletMaq() {
		List <TbBoleto> ListaSet = RecListBolMaq();
			if (!ListaSet.isEmpty()){	
			for(TbBoleto q: ListaSet){
				
				String met = Long.toString(q.getBoletoMeta());
				Integer bol = (Integer) q.getTbMaquina().getMaquinaCod();
				String g = Integer.toString(bol);
			
				
				window.getTxtMaquinaOperante().setText(g);
				window.getTxtBoletoMeta().setText(met);
				
		}
			}else
				window.getTxtOpQtd().setText("");
				}
		
	public List<TbBoleto> RecListBolMaq() {
		TbBoletoDAO dao= new TbBoletoDAO();
		long cond = (Long) window.getCmbBoletos().getSelectedItem(); 
		
		StringBuffer query = new StringBuffer ("from TbBoleto where boletoCod = "+ cond); 
				
					return dao.listByQuery(query.toString());
		}
	
	
	public List<TbOp> RecuperaListOp() {
		TbOpDAO dao= new TbOpDAO();
		long cond = (Long) window.getCmbOpCod().getSelectedItem(); 
		
		StringBuffer query = new StringBuffer ("from TbOp where opCod = "+ cond); 
				
					return dao.listByQuery(query.toString());
		}
		
	
	
	
	public List<TbBoleto> RecuperaListProdMaq() {
		TbBoletoDAO dao= new TbBoletoDAO();
		//long codOp = (Long)( window.getCmbOpCod().getSelectedItem()); 
		
		//StringBuffer query = new StringBuffer ("distinct boleto_codMaquina from TbBoleto");
		
		StringBuffer query = new StringBuffer ("from TbBoleto");
		
					return dao.listByQuery(query.toString());
		}
	
	//public void PreencherComboOperant() {
	//TbBoletoDAO  dao = new TbBoletoDAO();
	//List<TbBoleto> lista = dao.ListarPorBoleto(Long.parseLong(window.getTxtBoleto().getText()));
	//}
	
	
	
}
	
		

